package cn.sfrog.web.controller.system;

import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.enums.AgreementTypeEnum;
import cn.sfrog.system.domain.SysAgreementConf;
import cn.sfrog.system.service.ISysAgreementConfService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 协议配置Controller
 */
@Api(tags = "协议配置接口")
@RestController
@RequestMapping("/system/agreementConf")
public class SysAgreementConfController extends BaseController {
    @Resource
    private ISysAgreementConfService sysAgreementConfService;


    /**
     * 根据类型获取协议
     */
    @GetMapping("/getByType/{type}")
    public AjaxResult getByType(@PathVariable AgreementTypeEnum type){
        LambdaQueryWrapper<SysAgreementConf> wrapper = new LambdaQueryWrapper<SysAgreementConf>();
        wrapper.eq(SysAgreementConf::getContentType,type);
        SysAgreementConf cmsAgreementConf = sysAgreementConfService.getOne(wrapper);
        if(cmsAgreementConf != null){
            return AjaxResult.success("操作成功",cmsAgreementConf.getContent());
        }
        return AjaxResult.success();
    }


    /**
     * 编辑
     */
    @PutMapping
    public AjaxResult updateConf(@Valid @RequestBody SysAgreementConf formVO){
        sysAgreementConfService.updateBizAgreementConf(formVO);
        return AjaxResult.success();
    }

}
